<#include "/includes/vars.inc">  
<@pp.dropOutputFile />
<@pp.changeOutputFile name="${testJavaDir}${packageDir}/util/ValueGenerator.java" />

package ${project.@rootPackage}.util;

import java.util.Calendar;
import java.util.Date;
import java.util.Random;

/**
 * Util class for unit test
  * <#if project.@author[0]??>@author ${project.@author}</#if>
 */
public class ValueGenerator {

    private static Random random = new Random();
    private static Calendar calendar = Calendar.getInstance();

    public ValueGenerator() {
        //setCalendar(Calendar.getInstance());
    }

    public static int getArraysSize() {
        int i = random.nextInt(4) + 1;// arrays size from 1 to 5                
        return i;
    }

    public static Boolean getRandomBoolean() {
        return random.nextBoolean();

    }

    public static String getRandomByteString() {

        return "" + random.nextInt(128);
    }


    public static Calendar getCalendar() {
        // this has effect on getdate and getxmlcalendar too
        //Calendar c = super.getCalendar();
        calendar.add(Calendar.DAY_OF_YEAR, random.nextInt());
        return calendar;
    }

    public static Date getRandomDate() {
        //calendar.add(Calendar.DAY_OF_YEAR, random.nextInt());
        //return calendar.getTime();
        return new Date();
    }
  
    public static char getRandomChar() {
        return (char) random.nextInt(8);
    }


    public static String getRandomDecimalString() {
        return "" + random.nextFloat();
    }

  
    public static Object getRandomEnum(Class clazz) {
        Object[] enumConstants = clazz.getEnumConstants();
        return enumConstants[random.nextInt(enumConstants.length)];
    }

    public static String getRandomIntegerString() {
        // limited to 16 bits because we use this for shorts too
        return "" + random.nextInt(32768);
    }

  
    public static String getRandomString() {
        return getRandomString(3, 10);
    }

    public static String getRandomString(int minSize, int maxSize) {
        int n = getRandomInt(minSize, maxSize);
        byte b[] = new byte[n];
        for (int i = 0; i < n; i++) {
            b[i] = (byte) getRandomInt('a', 'z');
        }
        return new String(b);
    }

    public static int getRandomInt(int lo, int hi) {
        int n = hi - lo + 1;
        int i = random.nextInt() % n;
        if (i < 0) {
            i = -i;
        }
        return lo + i;
    }
    public static double getRandomDouble(int lo, int hi) {
        int n = hi - lo + 1;
        int i = random.nextInt() % n;
        if (i < 0) {
            i = -i;
        }
        return (double)lo + i;
    }
    
    public static Double getRandomDouble() {
        return random.nextDouble();
    }
    
     public static Integer getRandomInteger() {
        return random.nextInt();
    }
    
    public static Float getRandomFloat() {
        return random.nextFloat();
    }
}